﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PSE.Tools.SchemaComparer.WindowsApp
{
    /// <summary>
    /// Interaction logic for UcConfiguration.xaml
    /// </summary>
    public partial class UcConfiguration : UserControl
    {
        private Configurations _config;
        public UcConfiguration()
        {
            InitializeComponent();
            _config = new Configurations();
            _config.Load();
            this.Loaded += new RoutedEventHandler(UcConfiguration_Loaded);

        }

        void UcConfiguration_Loaded(object sender, RoutedEventArgs e)
        {
            txtCompareTool.Text = _config.ComparerToolPath;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
            dialog.Filter = "Executable File |*.exe";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtCompareTool.Text = dialog.FileName;
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                _config.ComparerToolPath = txtCompareTool.Text;
                _config.Save();
            }
            catch
            {
                MessageBox.Show(string.Format("Não foi possível salvar as configurações." + Environment.NewLine + "Por favor verifique as configurações de acesso do arquivo {0} e tente novamente.", _config.ConfigPath));
            }
        }
    }
}
